package com.sun.controller;

import com.sun.dto.UserDTO;
import com.sun.entity.R;
import com.sun.entity.User;
import com.sun.service.IUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author SunRui
 * @since 2024-12-11
 */
@RestController
@RequestMapping("/user")
@Tag(name = "用户控制器", description = "用户接口")
@CrossOrigin
public class UserController {

    @Autowired
    IUserService userService;

    // 通过小组Id获取用户列表
    @GetMapping("/squadId")
    @Operation(summary = "通过小组Id获取用户信息",description = "通过小组Id获取用户信息接口")
    @ApiResponses(value = {@ApiResponse(responseCode = "200",description = "成功"),
            @ApiResponse(responseCode = "404",description = "失败")})
    public R selectUserBySquadId(@Parameter(name = "小组id") Integer squadId){
        System.out.println("squaId:"+squadId);
        return R.success(userService.selectUserBySquadId(squadId));
    }

    // 添加用户信息
    @PostMapping()
    @Operation(summary = "添加用户信息",description = "添加用户信息接口")
    @ApiResponses(value = {@ApiResponse(responseCode = "200",description = "成功"),
            @ApiResponse(responseCode = "404",description = "失败")})
    public R addUser(@Parameter(name = "用户信息")@RequestBody UserDTO userDTO){
        System.out.println(userDTO.toString());
        return R.success(userService.addUser(userDTO));
    }

    // 删除用户
    // 添加用户信息
    @PostMapping("/delete")
    @Operation(summary = "删除用户信息",description = "删除用户信息接口")
    @ApiResponses(value = {@ApiResponse(responseCode = "200",description = "成功"),
            @ApiResponse(responseCode = "404",description = "失败")})
    public R deleteUserById(@Parameter(name = "用户id") Integer id,Integer squadId){
        System.out.println("id:"+id);
        System.out.println("squadId:"+squadId);
        return R.success(userService.deleteUserById(id,squadId));
    }
}
